import diff from "./diff"

export default class Component {
    constructor (props) {
        this.props = props
    }
    // 
    setState (state) {
        this.state = Object.assign({}, this.state, state)
        // 获取最新的要渲染的virtual对象
        let virtualDOM = this.render()
        // 获取旧的 virtualDOM对象 进行比对
        let oldDOM = this.getDOM()
        // 获取容器
        let container = oldDOM.parentNode
        // 实现dom比对更新
        diff(virtualDOM, container, oldDOM)
    }
    // 保存页面dom对象
    setDOM (dom) {
        this._dom = dom
    }
    // 获取页面dom对象
    getDOM () {
        return this._dom
    }
}